package com.ruoyi.common.utils.tencent;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class QQGroupMembers {
    private static final String API_URL = "";

    public static void main(String[] args) {
        String groupNumber = "123456"; // 用户输入的QQ群号
        try {
            String response = getGroupMembers(groupNumber);
            System.out.println("群成员信息: " + response);
        } catch (Exception e) {
            System.err.println("获取群成员失败: " + e.getMessage());
        }
    }

    private static String getGroupMembers(String groupNumber) throws Exception {
        URL url = new URL(API_URL + "?groupNumber=" + groupNumber);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");

        int responseCode = connection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            StringBuilder response = new StringBuilder();
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            return response.toString();
        } else {
            throw new Exception("API请求失败，状态码：" + responseCode);
        }
    }
}
